$(function(){
	changeHeaderMenu(4);
	changeMenu(0, 1);
	menuClick(0);
});

function menuClick(type) {
	$('.btn-cur').removeClass('btn-cur');
	if(type == 1) {
		$('.change_pwd').hide();
		$('.change_mobile').show();
		$('.change_menu:eq(1)').addClass('btn-cur');
	} else {
		$('.change_mobile').hide();
		$('.change_pwd').show();
		$('.change_menu:eq(0)').addClass('btn-cur');
	}
}

function changeVc(){
	$('.vcimg').attr('src','/cloud_ifw/common/verify_graphCode.action?_dc' + Math.random());
}

var get_mobile_code_ing = false;
function get_mobile_code() {
	if(get_mobile_code_ing)
		return;
	get_mobile_code_ing = true;
	var mobile = $('#mobile').val();
	if(!mobile) {
		alert('请输入手机号');
		return;
	}
	var r = $jValidator.valid('mobile', mobile);
	if(!r.result) {
		alert(r.msg);
		return;
	}
	$.getJSON('/cloud_ifw/member/memberbrow_getmobilecodeforchangemobi.action', {
		mobile: mobile
	}, function(data) {
		if(data.success && data.result) {
			time_verify_code = 60;
			set_time_verify_code();
			alert('验证码已发送');
		} else {
			alert(data.result.errors?data.result.errors:'获取验证码失败');
		}
		get_mobile_code_ing = false;
	});
}

var time_verify_code = 0;
function set_time_verify_code() {
	setTimeout(function() {
		if(time_verify_code > 0) {
			time_verify_code -= 1;
			$('#get_mobile_code').addClass('timeing');
			$('#get_mobile_code').attr('disabled', 'disabled');
			$('#get_mobile_code').html(time_verify_code + '秒后可重新获取');
			set_time_verify_code();
		} else {
			// 倒计时结束
			$('#get_mobile_code').removeClass('timeing');
			$('#get_mobile_code').removeAttr('disabled');
			$('#get_mobile_code').html('获取验证码');
		}
	}, 1000);
}

function change_pwd_ok(){
	var oldpwd = $('#oldpwd').val();
	if(!oldpwd) {
		alert('请输入原密码');
		return;
	}
	var password = $('#password').val();
	if(!password) {
		alert('请输入新密码');
		return;
	}
	if(oldpwd == password) {
		alert('新密码不能和原密码相同');
		return;
	}
	var password2 = $('#password2').val();
	if(!password2) {
		alert('请输入确认密码');
		return;
	}
	if(password != password2) {
		alert('密码和确认密码不一致');
		return;
	}
	var verifyCode = $('#verifyCode').val();
	if(!verifyCode) {
		alert('请输入验证码');
		return;
	}
	var url = '/cloud_ifw/member/memberbrow_changepwd.action';
	var data = {
		oldpwd: oldpwd,
		password: password,
		password2: password2,
		verifyCode: verifyCode
	};
	$.post(url, data, function(r) {
		var data = $.parseJSON(r);
		if(data.success && data.result) {
			alert('修改密码成功');
			location.reload();
		} else {
			alert(data.result.errors?data.result.errors:'修改密码失败');
		}
	});
}

function change_mobile_ok(){
	var mobile = $('#mobile').val();
	if(!mobile) {
		alert('请输入手机号');
		return;
	}
	var mobileCode = $('#mobileCode').val();
	if(!mobileCode) {
		alert('请输入手机验证码');
		return;
	}
	var verifyCode = $('#verifyCode').val();
	if(!verifyCode) {
		alert('请输入验证码');
		return;
	}
	var url = '/cloud_ifw/member/memberbrow_changemobile.action';
	var data = {
		mobile: mobile,
		mobileCode: mobileCode,
		verifyCode: verifyCode
	};
	$.post(url, data, function(r) {
		var data = $.parseJSON(r);
		if(data.success && data.result) {
			alert('修改手机号成功');
			location.reload();
		} else {
			alert(data.result.errors?data.result.errors:'修改手机号成功');
		}
	});
}